﻿using System;
using Zadani09.util;


namespace Zadani09.db.DAO
{
    public sealed class DAOTovarna
    {

        public static readonly DAOTovarna instance = new DAOTovarna();

        private DAOTovarna()
	    {}


        //omg to je nazev :D
        private Object nahrejImplementaci(string clazz)
        {
            
            Type typ = Type.GetType(clazz);

            if (typ == null)
            {
                //Console.WriteLine("Typ je null"); //nejaky log ?
                throw new ApplicationException("TYP JE NULL");
                //return null;
            }

            Object value = Activator.CreateInstance(typ);

            return value;    
        }

        public IUzivatelDAO getUzivatelDAO()
        {

            Object result = nahrejImplementaci(Constants.DAO_UZIVATEL_IMPL);

            if (!(result is IUzivatelDAO))
            {
                //throw neco mozna ?
            }

            return (IUzivatelDAO)result;
        }

        public IDiloDAO getDiloDAO()
        {
            Object result = nahrejImplementaci(Constants.DAO_DILO_IMPL);

            if (!(result is IDiloDAO))
            {
                //throw neco mozna ?
            }

            return (IDiloDAO)result;
        }

        public IUmelecDAO getUmelecDAO()
        {
            Object result = nahrejImplementaci(Constants.DAO_UMELEC_IMPL);

            if (!(result is IUmelecDAO))
            {
                //throw neco mozna ?
            }

            return (IUmelecDAO)result;
        }

        public IVstupenkaDAO getVstupenkaDAO()
        {
            Object result = nahrejImplementaci(Constants.DAO_VSTUPENKA_IMPL);

            if (!(result is IVstupenkaDAO))
            {
                //throw neco mozna ?
            }

            return (IVstupenkaDAO)result;
        }

        public IGalerieDAO getGalerieDAO()
        {
            Object result = nahrejImplementaci(Constants.DAO_GALERIE_IMPL);

            if (!(result is IGalerieDAO))
            {
                //throw neco mozna ?
            }

            return (IGalerieDAO)result;
        }

        public IVystavaDAO getVystavaDAO()
        {
            Object result = nahrejImplementaci(Constants.DAO_VYSTAVA_IMPL);

            if (!(result is IVystavaDAO))
            {
                //throw neco mozna ?
            }

            return (IVystavaDAO)result;
        }

        public ISerieDAO getSerieDAO()
        {
            Object result = nahrejImplementaci(Constants.DAO_SERIE_IMPL);

            if (!(result is ISerieDAO))
            {
                //throw neco mozna ?
            }

            return (ISerieDAO)result;
        }

    }
}
